package com.woniu.his.cms.client.config;


import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;

import java.io.InputStream;

public class OssUtil {

    static String id = "LTAI5tPigC6FXH8YT15bUPRA";
    static String secret = "8x1XgrBJPpO5Ka3eI1SjcZh9RUf9iy";
    static String endPoint = "oss-cn-chengdu.aliyuncs.com";



       //LTAI5tPigC6FXH8YT15bUPRA
      //8x1XgrBJPpO5Ka3eI1SjcZh9RUf9iy

    /**
     * 上传方法
     *
     * @param bucketName
     * @param fileName
     * @param file
     * @return
     */
    public static String uploadFile(String bucketName, String fileName, InputStream file) {
        OSS oss = new OSSClientBuilder().build("http://" + endPoint, id, secret);

        try {
            oss.putObject(bucketName, fileName, file);
            return "http://" + bucketName + "." + endPoint + "/" + fileName;
        } finally {
            if (oss != null) {
                oss.shutdown();
            }
        }
    }

    /**
     * 删除文件
     *
     * @param bucketName
     * @param fileName
     * @return
     */
    public  static boolean removeFile(String bucketName, String fileName) {
        OSS oss = new OSSClientBuilder().build("http://" + endPoint, id, secret);

        try {
            oss.deleteObject(bucketName, fileName);
            return true;
        } finally {
            if (oss != null) {
                oss.shutdown();
            }
        }


    }


}
